################################
# setup and proc
# ##############################
source -e -v user_scripts/global_setup.tcl
source -e -v user_scripts/block_setup.tcl
source -e -v user_scripts/loadInnovus.tcl

set current_step "place"
set previous_step "floorplan"

set report_dir "reports/${current_step}"
if {![file exist $report_dir]} {file mkdir $report_dir}

#####################################
# open design
# ##################################
restoreDesign ${DESIGN_LIBRARY}/${DESIGN_NAME}.${previous_step}.dat $DESIGN_NAME

# common setting
source -e -v user_scripts/common_setting.tcl


########################################
# AOCV
# #####################################
if {[file exists $AOCV_FILE]} {
		puts "INFO: Sourcing $AOCV_FILE"
		source -echo $AOCV_FILE
} elseif {$AOCV_FILE != ""} {
		puts "error: AOCV_FILE($AOCV_FILE) is invalid. Pls correct it."
}

############################################
# create path groups
############################################
if {[file exists $GROUP_PATH_FILE]} {
		puts "INFO: Sourcing $GROUP_PATH_FILE"
		source -echo $GROUP_PATH_FILE
} elseif {$GROUP_PATH_FILE != ""} {
		puts "error: GROUP_PATH_FILE($GROUP_PATH_FILE) is invalid. Pls correct it."
}

redirect -file $report_dir/${DESIGN_NAME}.path_group_option.rpt {reportPathGroupOptions}


############################################
# IO buffer
############################################
#if {[file exists $GROUP_PATH_FILE]} {
#		puts "INFO: Sourcing $GROUP_PATH_FILE"
#		source -echo $GROUP_PATH_FILE
#} elseif {$GROUP_PATH_FILE != ""} {
#		puts "error: GROUP_PATH_FILE($GROUP_PATH_FILE) is invalid. Pls correct it."
#}

#redirect -file $report_dir/${DESIGN_NAME}.path_group_option.rpt {reportPathGroupOptions}

saveDesign ${DESIGN_LIBRARY}/${DESIGN_NAME}.pre_place

############################################
# delete Tie cells from netlist
############################################
#foreach cell [dbGet -e -u top.insts.cell.name TIE*] {
#		deleteTieHiLo -cell $cell
#}

############################################
# place setting
############################################
source -e user_scripts/common_setting.place.tcl

############################################
#Pre-place customizations
############################################
if {[file exists $PRE_SCRIPT($current_step)]} {
		puts "INFO: Sourcing $PRE_SCRIPT($current_step)"
		source $PRE_SCRIPT($current_step)
} else {
		puts "WARN: $PRE_SCRIPT($current_step) not exist. Skip to source it."
}

#refinePlace

############################################
# Core command
############################################
setOptMode -addInstancePrefix PLACE
setOptMode -addNetPrefix PLACE_NET
if {[file exists $USER_PLACE_OPT_SCRIPT]} {
		puts "INFO: Sourcing $USER_PLACE_OPT_SCRIPT"
		source $USER_PLACE_OPT_SCRIPT
} else {
		place_opt_design
}



checkDesign -all >> check_design_preplace.txt


############################################
# Add tie cells
############################################
source -e -v user_scripts/add_tie_cell.tcl


############################
# PG connection
# ##########################
source -e -v user_scripts/pg_connection.tcl


#####################################
# Post-init_design customizations
# ##################################
if {[file exists $POST_SCRIPT($current_step)]}  {
		puts "INFO: Sourcing $POST_SCRIPT($current_step)"
		source $POST_SCRIPT($current_step)
} else {
		puts "WARN: $POST_SCRIPT($current_step) not exist. Skip to source it."
}


source -e -v user_scripts/pg_connection.tcl

saveDesign ${DESIGN_LIBRARY}/${DESIGN_NAME}.${current_step}


###################################################
# Report
# ##############################################
if {$REPORT_QOR($current_step)} {
		source -e ./user_scripts/report_qor.tcl
} else {
		puts "INFO: Skip report for step: $current_step"
}


############################
# PG connection
# ##########################
source -e -v user_scripts/pg_connection.tcl


#####################################
# Post-init_design customizations
# ##################################
if {[file exists $POST_SCRIPT($current_step)]}  {
		puts "INFO: Sourcing $POST_SCRIPT($current_step)"
		source $POST_SCRIPT($current_step)
} else {
		puts "WARN: $POST_SCRIPT($current_step) not exist. Skip to source it."
}


date > ${current_step}

exit






